package com.group.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.group.dao.GeneralBeanDao;
import com.group.dao.UserDao;
import com.group.model.User;
import com.group.model.UserFollow;

@Service
public class UserService {

	@Autowired
	GeneralBeanDao beanDao;

	@Autowired
	UserDao userDao;

	/**
	 * 补充是否关注
	 * 
	 * @param users
	 * @param loginUserId
	 */
	public void fillUser(List<User> users, Long loginUserId) {
		if (loginUserId != null) {
			for (User user : users) {
				UserFollow para = new UserFollow();
				para.setUserId(loginUserId);
				para.setFollowUserId(user.getId());
				if (beanDao.queryOne(para) != null) {
					user.setIsLike(true);
				} else {
					user.setIsLike(false);
				}
			}
		}
	}

	/**
	 * 根据id查询用户
	 * 
	 * @param userId
	 * @return
	 */
	// @Cacheable("getUser")
	public User getUser(Long userId) {
		User user = beanDao.quickQueryOne(User.class, "id", userId);
		user.setUuid(null);
		user.setNewsCount(userDao.queryUserPublishNewsCount(userId));
		return user;
	}

}
